package com.yulinlin.authorization;

import com.yulinlin.authorization.util.OauthUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@Component
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor {

    private List<String> keys = Arrays.asList("Authorization");

    @Override
    public void apply(RequestTemplate template) {
        // 业务逻辑


        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if(requestAttributes != null){
            HttpServletRequest request =  requestAttributes.getRequest();
            for (String key : keys) {
                template.header(key,request.getHeader(key));
            }
        }


    }

}
